<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CC的办公系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
	.ui-datepicker table {
		border: 0;
	}
	.yform .type-check label {
		width: 6em;
		display: inline-block;
	}
   .subcl,.subcr,.subc {
    padding-bottom: 100em;
    margin-bottom: -100em;
  }
	h6 {
		background: #600;
		color: white;
		font-weight: bold;
		padding: 5px 10px;
	}
	#tablelist{
		font-family:宋体;
	}
</style>
<script type="text/javascript">
	$(function() {
		$("#form1").validationEngine();
		$("input:checked").next().next().prop("disabled",false)
		$("input[name='post']").click(function(){
			if($(this).prop("checked")){
				$(this).next().next().prop("disabled",false)
			}else{
				$(this).next().next().prop("disabled",true)
			}
		});
	});
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),0,15) then call JumpErrorPage(2)
id=request("id")
submit=request("submit")
If submit<>"" Then
	conn.BeginTrans
	username=LCase(request("username"))
	password=request("password")
	fullname=request("fullname")
	active=request("active")
	wan=request("wan")
	if active="" then active=false
	if wan="" then wan=false
	if submit="新增" then
		sql="insert into username(username,[password],fullname,active,wan) values('"&username&"','"&password&"','"&fullname&"',"&active&","&wan&")"
		'response.write(sql)
		'response.end
		newuserid=ExecuteCommand(sql,true)
	end if
	if submit="保存" then
		sql="update username set username='"&username&"',[password]='"&password&"',fullname='"&fullname&"',active="&active&",wan="&wan&" where id="&id
		call ExecuteCommand(sql,false)
		sql="delete * from flag where username="&id
		call ExecuteCommand(sql,false)
		newuserid=id
	end if
	for i=1 to request.form("post").count
		post=request.form("post")(i)
		flag=request.form("flag")(i)
		sql="insert into flag(username,post,flag) values("&newuserid&","&post&","&flag&")"
		call ExecuteCommand(sql,flase)
	next
	if err.number=0 then 
		conn.CommitTrans  '如果没有conn错误，则执行事务提交
	else
		conn.RollbackTrans '否则回滚
		'回滚后的其他操作
		'strerr=err.Description
		url=request.ServerVariables("http_host")&request.ServerVariables("url")
		Response.Write "数据库错误！<br /><font color=red>Error # " & CStr(Err.Number) & "<br />" & Err.Description & "<br />Source: " & Err.Source &"<br />错误页面："&url&"</font><br />"
		Response.End
	end if

end if
if id<>"" then
	Set rs = Server.CreateObject("ADODB.Recordset")
	sql = "select * from username left join flag on username.id=flag.username where id="&id
	rs.Open sql,conn,1,1
	username=rs("username.username")
	password=rs("password")
	fullname=rs("fullname")
	active=rs("active")
	wan=rs("wan")
	aaFlag=rs.getrows(,,array("post","flag"))
	rs.close
	set rs=nothing
' else
	' dim aaFlag(1,0)
	' aaFlag(0,0)=null
	' aaFlag(1,0)=null
end if
%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
	<div id="col3" role="main">
		<div id="col3_content" class="clearfix">
			<form id="form1" name="form1" method="post" class="yform" role="application">
				<div class="subcolumns equalize">
					<div class="c50l">
						<div class="subcl">
							<h6>基本资料</h6>
							<div class="type-text">
								<label for="username">用户名*</label>
								<input name="username" class="validate[required,minSize[3],maxSize[10],custom[onlyLcaseLetter]]" maxlength="10" id="username" type="text" value="<%=username%>" />
							</div>
							<div class="type-text">
								<label for="password">密码*</label>
								<input name="password" class="validate[required,minSize[6],maxSize[10],custom[onlyPassword]]" maxlength="10" id="password" type="password" value="<%=password%>" />
							</div>
							<div class="type-text">
								<label for="fullname">姓名*</label>
								<input name="fullname" class="validate[required,minSize[2],maxSize[4]]" maxlength="4" id="fullname" type="text" value="<%=fullname%>" />
							</div>
							<div class="type-check">
								<input name="active" id="active" type="checkbox" value="true" <%if active then response.write("checked='checked'")%> />
								<label for="active">激活用户</label>
							</div>
							<div class="type-check">
								<input name="wan" id="wan" type="checkbox" value="true" <%if wan then response.write("checked='checked'")%> />
								<label for="wan">公网访问</label>
							</div>
						</div>
					</div>
					<div class="c50r">
						<div class="subcr">
							<h6>权限管理</h6>
							<%
								Set rs_post = Server.CreateObject("ADODB.Recordset")
								sql_post = "SELECT *  FROM post order by id"
								rs_post.Open sql_post,conn,1,1
								do while not rs_post.eof
							%>
							<div class="type-check">
								<input name="post" id="post<%=rs_post("id")%>" type="checkbox" value="<%=rs_post("id")%>" <%if CheckPost(aaFlag,rs_post("id")) then response.write("checked='checked'")%> />
								<label for="post<%=rs_post("id")%>"><%=rs_post("post")%></label>
								<select name="flag" disabled="disabled">
								<%
									aAuthKey=dAuthority.keys
									aAuthItem=dAuthority.items
									for iAuthLoop=0 to dAuthority.count-1
								%>
									<option value="<%=aAuthKey(iAuthLoop)%>" <%if CheckPost(aaFlag,rs_post("id")) and GetFlagValue(aaFlag,rs_post("id"))=cint(aAuthKey(iAuthLoop)) then response.write("selected")%>><%=aAuthItem(iAuthLoop)%></option>
								<%
									next
								%>
								</select>
							</div>
							<%
									rs_post.movenext
								loop
								rs_post.close
								set rs_post=nothing
							%>
						</div>
					</div>
				</div>
				<div  class="type-button">
					<%if id="" then%>
					<input type="submit" name="submit" value="新增" />
					<%end if%>
					<%if id<>"" and id<>1 then%>
					<input type="submit" name="submit" value="保存" />
					<%end if%>
				</div>
			</form>
			<table id="tablelist" class="full">
				<thead>
					<tr><th colspan="5" scope="col">用户明细</th></tr>
				</thead>
				<tbody>
					<tr>
						<th scope="col">用户名</th>
						<th scope="col">姓名</th>
						<th scope="col">状态</th>
						<th scope="col">公网访问</th>
						<th scope="col">权限</th>
					</tr>
					<%
						sql = "select * from username"
						Set rs = Server.CreateObject("ADODB.Recordset")
						rs.Open sql,conn,1,1
						do while not rs.eof
					%>
					<tr>
						<th class="sub" scope="row"><a href="username.asp?id=<%=rs("id")%>"><%=rs("username")%></a></th>
						<td><%=rs("fullname")%></td>
						<td><%if rs("active") then response.write("激活")%></td>
						<td><%if rs("wan") then response.write("是")%></td>
						<td>
						<%
							Set rs_flag = Server.CreateObject("ADODB.Recordset")
							sql_flag="SELECT post.post,flag from flag inner join post on flag.post=post.id where username="&rs("id")
							rs_flag.Open sql_flag,conn,1,1
							do while not rs_flag.eof
								response.write(FillSpace(rs_flag("post"),12)&"："&dAuthority(cstr(rs_flag("flag")))&"<br />")
								rs_flag.movenext
							loop
							rs_flag.close
							set rs_flag=nothing
						%>
						</td>
					</tr>
					<%
							rs.movenext
						loop
						rs.close
						set rs=nothing
					%>
				</tbody>
			</table>
		</div>
	</div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

